package com.it.Mapper;

import com.it.pojo.Flight;
import com.it.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Select("select * from `order`,orderdetail where `order`.o_number = orderdetail.o_number and `order`.idNumber = #{idNumber}")
    List<Order> OList(String idNum);

    @Insert("insert into `order` (o_number, idNumber, o_time) values (#{oNumber},#{idNumber},#{oTime})")
    void OAdd1(Order order);

    @Insert("insert into orderdetail (f_number, o_number, sort, seat) values (#{fNumber},#{oNumber},#{sort},#{seat})")
    void OAdd2(Order order);

    @Update("update flight set ticket = ticket - 1 where f_number = #{fNumber}")
    void reduceTickets(Order order);

    @Update("update flight f,orderdetail od set ticket = ticket + 1 where od.o_number = #{oNumber} and od.f_number = f.f_number")
    void increaseTickets(String oNumber);

    @Update("update `order` set o_status = 2 where o_number = #{oNumber}")
    void ORefund(String oNumber);

    @Select("select f.f_number from `order` o,orderdetail od,flight f where f.f_number = od.f_number and od.o_number = o.o_number and o.idNumber = #{idNumber} and o_status = 1")
    List<String> getFNumByIdNum(String idNumber);

    @Select("select f.f_number from flight f,orderdetail od where f.f_number = od.f_number and od.o_number = #{oNumber}")
    List<String> getFNumByONum(String oNumber);

    @Update("update `order` set o_status = 3 where o_number = #{oNumber}")
    void ORebook(String oNumber);

    @Delete("delete from `order` where o_number = #{oNumber}")
    void ODelete(String oNumber);

    @Select("select * from `order`,orderdetail where `order`.o_number = orderdetail.o_number and `order`.o_number = #{oNumber}")
    List<Order> getOrderById(String oNumber);
}
